package com.wbc.demo.passwordUtil;

import com.alibaba.druid.filter.config.ConfigTools;


/**
 * @author 389561407@qq.com
 * @version 1.0
 * @since 2022-12-20
 *
 * 生成密文密码 使用依赖
 *
 *         <dependency>
 *             <groupId>com.alibaba</groupId>
 *             <artifactId>druid-spring-boot-starter</artifactId>
 *             <version>1.2.5</version>
 *         </dependency>
 *
 *
 *
 */
public class DruidPassword {

    /**
     * spring:
     *   # MySQL 配置
     *   datasource:
     *     driver-class-name: com.mysql.cj.jdbc.Driver
     *     type: com.alibaba.druid.pool.DruidDataSource
     *     druid:
     *       url: jdbc:mysql://localhost:3306/test1?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
     *       username: root
     *       password: 这里修改为生成的 password
     *       # encrypt config
     *       filters: config
     *       connect-properties:
     *         config.decrypt: true
     *         config.decrypt.key: 这里修改为生成的 publicKey
     *
     * @param args
     * @throws Exception
     */

    public static void main(String[] args) throws Exception {
        String password = "root";
        String[] arr = ConfigTools.genKeyPair(512);
        System.out.println("privateKey:" + arr[0]);
        System.out.println("publicKey:" + arr[1]);
        System.out.println("password:" + ConfigTools.encrypt(arr[0], password));
    }
}
